﻿using Microsoft.Web.Services3.Security.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Wicresoft.EKA.Atrium.WCF
{
    class ClientMessageInspector : IClientMessageInspector
    {

        private const string USER_AGENT_HTTP_HEADER = "user-agent";

        private string m_userAgent;

        public ClientMessageInspector(string userAgent)
        {
            this.m_userAgent = userAgent;
        }

        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {

        }

        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {


            UsernameToken ut = new UsernameToken("Demo", "Pass01!", PasswordOption.SendHashed);

            XmlElement securityElement = ut.GetXml(new XmlDocument());

            MessageHeader myHeader = MessageHeader.CreateHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", securityElement, false);
            request.Headers.Add(myHeader);

            return null;
        }
    }
}
